package com.zxy.service;

import com.zxy.dao.PermissionsDao;
import com.zxy.dao.RolePermissionsDao;
import com.zxy.model.Permissions;
import com.zxy.model.PermissionsQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionsService {
    @Autowired
    PermissionsDao permissionsDao;
    @Autowired
    RolePermissionsDao rolePermissionsDao;

    public List<Permissions> select(PermissionsQuery query) {
        return permissionsDao.select(query);
    }

    public int insert(Permissions permissions) {
        return permissionsDao.insert(permissions);
    }

    public int update(Permissions permissions) {
        return permissionsDao.update(permissions);
    }

    public int delete(Integer id) {
        rolePermissionsDao.deleteByPermissionId(id);
        return permissionsDao.delete(id);
    }

    public List<Permissions> selectRoleId(Integer id) {
        return permissionsDao.selectPermissionsByRoleId(id);
    }

    public List<Permissions> selectUserId(Integer id) {
        return permissionsDao.selectPermissionsByUserId(id);
    }
}
